package pers.liyan.shi.springcloud.producerticketclient.client.hystrix;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import pers.liyan.shi.springcloud.producerticketclient.domain.Ticket;
import pers.liyan.shi.springcloud.producerticketclient.client.TicketClient;

/**
 * 处理调用失败的情况, 使用 fallback 指定
 * 无法获取调用失败的原因(使用 fallbackFactory)
 *
 * @author shily
 * @date 2019/4/21 12:48
 *
 * 此处只能使用 @Component 注解, 同时要加入 spring 扫描路径
 */
@Component
public class HystrixClientFallback implements TicketClient {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public Ticket buyTicket(String movieName) {
        logger.warn("调用失败,触发熔断机制");
        return new Ticket(movieName, null, null);
    }
}
